package com.aliyun.messagemgt.service.impl;
import com.aliyun.messagemgt.application.service.Impl.ChannelServiceImpl;
import com.aliyun.messagemgt.dto.base.FourAObjectEntity;
import com.aliyun.messagemgt.dto.PushChannelAdd;
import com.aliyun.messagemgt.dto.query.PushChannelQuery;
import com.aliyun.messagemgt.repository.mappers.MsgSourceMapper;
import com.aliyun.messagemgt.repository.mappers.PushChannelMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.annotation.Rollback;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: li.wy
 * @create: 2020-11-19
 **/
@RunWith(MockitoJUnitRunner.class)
public class ChannelServiceImplTest {

    @InjectMocks
    private ChannelServiceImpl channelService;

    @Mock
    private PushChannelMapper pushChannelMapper;

    @Mock
    private MsgSourceMapper msgSourceMapper;

    @Test
    @Rollback
    public void testSavePushChannel() {
        PushChannelAdd channelAdd = new PushChannelAdd();
        channelAdd.setPushChannelDescription("单元测试");
        try {
            List<FourAObjectEntity> list = new ArrayList<>();
            channelAdd.setOwners(list);
            channelAdd.setUserName("1");
            Mockito.when(pushChannelMapper.selectByDescription(Mockito.any())).thenReturn(0);
            Mockito.when(pushChannelMapper.insertPushChannel(Mockito.any())).thenReturn(1);
            channelService.savePushChannel(channelAdd);
        } catch (Exception e) {

        }

    }

    @Test
    @Rollback
    public void testCommitPushChannel() {
        PushChannelAdd channelAdd = new PushChannelAdd();
        channelAdd.setPushChannelDescription("单元测试");
        try {
            List<FourAObjectEntity> list = new ArrayList<>();
            channelAdd.setOwners(list);
            channelAdd.setUserName("1");
            Mockito.when(pushChannelMapper.selectByDescription(Mockito.any())).thenReturn(0);
            Mockito.when(pushChannelMapper.insertPushChannel(Mockito.any())).thenReturn(1);
            channelService.commitPushChannel(channelAdd);
        } catch (Exception e) {

        }
    }

    /*@Test
    @Rollback
    public void testListPushChannel() {
        try {
            PushChannelQuery pushChannelQuery = new PushChannelQuery();
            pushChannelQuery.setPageNum(5);
            pushChannelQuery.setPageSize(5);
            List<PushChannelList> list = new ArrayList<>();
            Mockito.when(pushChannelMapper.listPushChannel(Mockito.any())).thenReturn(list);
            Mockito.when(pushChannelMapper.queryTopChannel(Mockito.any())).thenReturn(list);
            Mockito.when(pushChannelMapper.listPushChannelNoTop(Mockito.any())).thenReturn(list);
            channelService.listPushChannel(pushChannelQuery);
        } catch (Exception e) {

        }
    }*/

    @Test
    @Rollback
    public void testTopChannel() {
        try {
            PushChannelQuery pushChannelQuery = new PushChannelQuery();
            pushChannelQuery.setTopStatus(1);
            pushChannelQuery.setPushChannelId(1L);
            Mockito.when(pushChannelMapper.topPushChannel(Mockito.any())).thenReturn(1);
            channelService.topChannel(pushChannelQuery);
        } catch (Exception e) {

        }
    }

    @Test
    @Rollback
    public void testDelPushChannel() {
//        try {
//            PushChannelQuery pushChannelQuery = new PushChannelQuery();
//            pushChannelQuery.setPushChannelId(1);
//            Mockito.when(msgSourceMapper.queryChannelState(Mockito.any())).thenReturn(1);
//            Mockito.when(pushChannelMapper.delPushChannel(Mockito.any())).thenReturn(1);
//            channelService.delPushChannel(pushChannelQuery);
//        } catch (Exception e) {
//
//        }
    }

    @Test
    @Rollback
    public void testModPushChannel() {
        PushChannelAdd channelAdd = new PushChannelAdd();
        channelAdd.setPushChannelDescription("单元测试");
        channelAdd.setPushChannelId(1L);
        channelAdd.setUserName("1");
        try {
            List<FourAObjectEntity> list = new ArrayList<>();
            channelAdd.setOwners(list);
            channelAdd.setUserName("1");
            Mockito.when(pushChannelMapper.selectByDescription(Mockito.any())).thenReturn(0);

            Mockito.when(pushChannelMapper.modPushChannel(Mockito.any())).thenReturn(1);
            channelService.modPushChannel(channelAdd);
        } catch (Exception e) {

        }
    }

    /*@Test
    @Rollback
    public void testDetailChannel() {

        try {
            PushChannelQuery pushChannelQuery = new PushChannelQuery();
            pushChannelQuery.setPushChannelId(1);
            PushChannelList pushChannelList = new PushChannelList();
            pushChannelList.setOwner("1");

            Mockito.when(pushChannelMapper.queryChannelDetail(Mockito.any())).thenReturn(pushChannelList);
            channelService.detailChannel(pushChannelQuery);
        } catch (Exception e) {

        }
    }
*/
    @Test
    @Rollback
    public void testTestConnection() {
        PushChannelAdd channelAdd = new PushChannelAdd();
        channelAdd.setPushChannelDescription("单元测试");
        channelAdd.setPushChannelId(1L);
        channelAdd.setChannelType(6);
        try {
            channelService.testConnection(channelAdd);
        } catch (Exception e) {

        }
    }

    @Test
    @Rollback
    public void testChannelsTypes() {
        try {
            channelService.channelsTypes(new PushChannelQuery());
        } catch (Exception e) {

        }
    }
}